﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Collections.Specialized;

using Husb.Util;
using Husb.Util.Enum;
using CentralOffice.Task.Data;
using CentralOffice.Task.BusinessActions;

using ApplicationTable = CentralOffice.Task.Data.ApplicationDataSet.ApplicationsDataTable;
using ApplicationRow = CentralOffice.Task.Data.ApplicationDataSet.ApplicationsRow;


using ApprovalTable = CentralOffice.Task.Data.ApprovalDataSet.ApprovalsDataTable;
using ApprovalRow = CentralOffice.Task.Data.ApprovalDataSet.ApprovalsRow;


namespace CentralOffice.WebClient.Tasks
{
    public partial class MyApplication : PageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void ods_Selecting(object sender, ObjectDataSourceSelectingEventArgs e)
        {
            int status = EnumUtil.GetInt32(SiteConstants.ApprovalStatus, CategoryDataSourceType.Xml, "通过");

            IOrderedDictionary parameters = e.InputParameters;
            ApplicationRow application = (new ApplicationDataSet()).Applications.NewApplicationsRow();
            application.Applicant = CommonUtil.TrimAll(ApplicationContext.ActualUserName);
            //parameters["whereClause"] = task.FilterExpression;
            parameters["whereClause"] = application.FilterExpression ;
            //parameters.Remove("Id");
        }

        protected void gv_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                ApplicationRow application = ((DataRowView)e.Row.DataItem).Row as ApplicationRow;

                HyperLink a = e.Row.Cells[7].Controls[0] as HyperLink;
                if (!application.IsProcessIdNull())
                {
                    a.NavigateUrl = a.NavigateUrl.Replace("ApplicationUpdate", "ApplicationUpdatePre");
                }

                int pending = EnumUtil.GetInt32(SiteConstants.ApprovalStatus, CategoryDataSourceType.Xml, "待审");
                //int rejection = EnumUtil.GetInt32(SiteConstants.ApprovalStatus, CategoryDataSourceType.Xml, "否决");

                //if (application.Status == rejection)
                //{
                //    e.Row.Cells[5].Text = "<span class=\"warning\">否决</span>";
                //}

                TableCell statusCell = e.Row.Cells[6];
                if (statusCell.Text == "在审")
                {
                    statusCell.Style.Add(HtmlTextWriterStyle.Color, SiteUtil.GetExceptionalDataColor());
                }
                else if (statusCell.Text == "通过")
                {
                    statusCell.Style.Add(HtmlTextWriterStyle.Color, "#0f0");
                }
                else if (statusCell.Text == "否决")
                {
                    statusCell.Style.Add(HtmlTextWriterStyle.Color, "#f00");
                }
                else if (statusCell.Text == "已执行")
                {
                    statusCell.Style.Add(HtmlTextWriterStyle.Color, "#6f0");
                }

                if (application.Status < pending + 1 )//|| application.Status == rejection
                {
                    e.Row.Cells[7].Controls[0].Visible = true;
                }
                else
                {
                    e.Row.Cells[7].Controls[0].Visible = false;
                }
            }
        }
    }
}
